package hms.rewards;

import java.sql.*;
import java.util.Arrays;
import java.util.Iterator;

import hms.database.*;

/*This class controls all interactions with 
 * Reward_Account table in DB
 * 
 * @author Edgar Onukwugha*/

public class RewardAccount extends DBRowObject{

	private int guest_ID;
	private int member_ID;
	private int reward_program_ID;
	private int point_balance;
	private Boolean is_subscribed;
	private Date subscription_begin_date;
	private Date subscription_end_date;
	
	public RewardAccount(){
		super();
		guest_ID = -1;
		member_ID = -1;
		reward_program_ID = -1;
		point_balance = -1;
		is_subscribed = false;
		subscription_begin_date = null;
		subscription_end_date = null;
		
	}
	
	public RewardAccount(int reward_account_ID){
		super(reward_account_ID);
	}
	
	/////////////////////////////////////////////////
	/////               SETTERS                //////
	/////////////////////////////////////////////////
		
	public void setGuestID(int i){
		guest_ID = i;
		markAsChanged();
	}
	
	public void setMemberID(int i){
		member_ID = i;
		markAsChanged();
	}
	
	public void setRewardProgramID(int i){
		reward_program_ID = i;
		markAsChanged();
	}
	
	public void setPointBalance(int i){
		point_balance = i;
		markAsChanged();
	}
	
	public void setIsScubscribed(Boolean i){
		is_subscribed = i;
		markAsChanged();
	}
	
	public void setSubscriptionBeginDate(Date i){
		subscription_begin_date = i;
		markAsChanged();
	}
	
	public void setSubscriptionEndDate(Date i){
		subscription_end_date = i;
		markAsChanged();
	}
	/////////////////////////////////////////////////
	/////               GETTERS                //////
	/////////////////////////////////////////////////
	
	public int getGuestID(){
		return guest_ID;
	}
	
	public int getMemberID(){
		return member_ID;
	}
	
	public int getRewardProgramID(){
		return reward_program_ID;
	}
	
	public int getPointBalance(){
		return point_balance;
	}
	
	public Boolean getIdSubscribed(){
		return is_subscribed;
	}
	
	public Date getSubscriptionBeginDate(){
		return subscription_begin_date;
	}
	
	
	
	public Date getSubscriptionEndDate(){
		return subscription_end_date;
	}
	
	
	@Override
	protected String[] getFieldNames() {
		String[] output = new String[7];
		output[0] = "GUEST_ID";
		output[1] = "MEMBER_ID";
		output[2] = "REWARD_PROGRAM_ID";
		output[3] = "POINT_BALANCE";
		output[4] = "IS_SUBSCRIBED";
		output[5] = "SUBSCRIPTION_BEGIN_DATE";
		output[6] = "SUBSCRIPTION_END_DATE";
		
		return output;
	}

	@Override
	protected void loadPreparedStatement(PreparedStatement stmt)
			throws SQLException {
		stmt.setInt(1, guest_ID);
		stmt.setInt(2, member_ID);
		stmt.setInt(3, reward_program_ID);
		stmt.setInt(4, point_balance);
		stmt.setBoolean(5, is_subscribed);
		stmt.setDate(6, subscription_begin_date);
		stmt.setDate(7, subscription_end_date);
		
	}

	@Override
	protected String getUniqueIdentifierFieldName() {
		// TODO Auto-generated method stub
		return "REWARD_ACCOUNT_ID";
	}

	@Override
	protected String getTableName() {
		// TODO Auto-generated method stub
		return "REWARD_ACCOUNT";
	}

	@Override
	protected void loadFromDatabase(ResultSet rs) throws SQLException {
		Iterator<String> i = Arrays.asList(getFieldNames()).iterator();
		guest_ID = rs.getInt(i.next());
		member_ID = rs.getInt(i.next());
		reward_program_ID = rs.getInt(i.next());
		point_balance = rs.getInt(i.next());
		is_subscribed = rs.getBoolean(i.next());
		subscription_begin_date = rs.getDate(i.next());
		subscription_end_date = rs.getDate(i.next());
		
	}

	@Override
	protected boolean allowDuplicateRows() {
		// TODO Auto-generated method stub
		return false;
	}

}
